#include "float.h"

FLOAT_I::FLOAT_I()
{
    data = 0;
    dec_pos = 0;
}

FLOAT_I::FLOAT_I(char* str_data)
{
    str2floati(str_data);
}

void FLOAT_I::str2floati(char* str_data)
{
    bool dec_detected = false,sign = false;
    int i=0;
    data = 0;
    dec_pos = 0;
    
    if(str_data[0] == '+' || str_data[0] == '-')
    {    
        sign = true;
        i++;
    }
    for(;str_data[i]!='\0';i++)
    {        
        if(dec_detected)
            dec_pos++;            
        
        if(ISDIGIT(str_data[i]))
            data = 10*data + TODIGIT(str_data[i]);
        else if(str_data[i] == '.')
            dec_detected = true;        
    }
    
    if(sign && str_data[0] == '-')
        data = -data;
}

int32 FLOAT_I::toInt()
{
    return (data/power10(dec_pos));
}

int32 FLOAT_I::floatinch_to_micron()
{
    //multiply with 25400    
    int Exp = dec_pos - 2;
    if(Exp>=0)
        return ((data * 254)/(power10(Exp)));
    else        
        return ((data * 254)*(power10(-Exp)));
}

int32 FLOAT_I::floatmm_to_micron()
{
    //multiply with 1000
    int Exp = dec_pos - 3;
    if(Exp >= 0)        
        return (data/power10(Exp));
    else
        return(data * power10(-Exp));
}

int32 FLOAT_I::floatcm_to_micron()
{
    //multiply with 100
    int Exp = dec_pos - 2;
    if(Exp >= 0)        
        return (data/power10(Exp));
    else
        return(data * power10(-Exp));
}

void FLOAT_I::getPrivateData(int32 &data_ret,int &dec_pos_ret)
{
    data_ret = this->data;
    dec_pos_ret = this->dec_pos;
}
